package com.zwcl.glass.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zwcl.glass.goods.dto.TagSpuDto;
import com.zwcl.glass.goods.entity.GoodsImages;
import com.zwcl.glass.goods.entity.GoodsSpu;
import com.zwcl.glass.goods.mapper.GoodsSpuMapper;
import com.zwcl.glass.goods.service.GoodsBaseService;
import com.zwcl.glass.goods.service.GoodsSpuService;
import com.zwcl.common.mybatis.service.impl.BaseServiceImpl;
import com.zwcl.glass.goods.vo.GoodsDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xieyongping
 * @since 2021-01-13
 */
@Service
public class GoodsSpuServiceImpl extends GoodsBaseService<GoodsSpuMapper, GoodsSpu> implements GoodsSpuService {


    @Autowired
    private GoodsSpuMapper goodsSpuMapper;
    /**
     * 由于没有自定义的id生成器，key采用#cateId的方式会报错
     * @param cateId
     * @return
     */
    @Override
    @Cacheable(value = ZWCL_GLASS_GOODS_SPU_CACHE, key = "#a0")
    public List<GoodsSpu> getSpusById(Integer cateId){
        return this.list(new LambdaQueryWrapper<GoodsSpu>().eq(GoodsSpu::getCateId, cateId));
    }

    /**
     * 关键字搜索，直接从库中检索
     * @return
     */
    @Override
    public Page<GoodsSpu> getSpusByTag(Page<GoodsSpu> page, TagSpuDto dto) {
        return goodsSpuMapper.getSpusByTag(page,dto);
    }

    /**
     * 可能查询效率堪忧，因为有多个标签，并且只能用Like
     * @param tags
     * @return
     */
    @Override
    public List<GoodsSpu> listSpuByTag(String[] tags) {
        return null;
    }

}
